<template>
  <!-- 分类组件 -->
   <div class="app-head-nav">
    <ul class="navs">
        <li class="home"><router-link to="/">首页</router-link></li>
        <li v-for="items in list" :key="items.id" @mousemove="show(items)" @mouseleave="hide(items)">
          <router-link @click="hide(items)" :to="`/category/${items.id}`">{{ items.name }}</router-link>
          <div class="layer" :class="{open:items.open}">
            <ul>
              <li v-for="item in items.children" :key="item.id" @click="hide(items)">
                <router-link :to="`/category/sub/${item.id}`">
                  <img :src="item.picture" alt="">
                  <p>{{ item.name }}</p>
                </router-link>
              </li>
            </ul>
          </div>
        </li>
      </ul>
   </div>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
export default {
  name: 'appHeadNav',
  setup () {
    const store = useStore()
    const list = computed(() => {
      return store.state.category.list
    })
    console.log(list)

    const show = (item) => {
      store.commit('category/show', item)
    }
    const hide = (item) => {
      store.commit('category/hide', item)
    }
    console.log(list, '4')
    return { list, show, hide }
  }
}
</script>

<style lang="less" scoped>
.app-head-nav {
  position: relative;
  .navs {
      display: flex;
      justify-content: center;
      padding-left:40px;
      width: 820px;
      >li {
        margin-right: 40px;
        width: 38px;
        text-align: center;
        >a {
          font-size: 16px;
          line-height: 32px;
          height: 32px;
          display: inline-block;
        }
        &:hover {
          >a {
            color: @xtxColor;
            border-bottom: 1px solid @xtxColor;
          }
          // .layer {
          //   height: 132px;
          //   opacity: 1;
          // }
        }
      }
    }
    .layer {
      &.open {
        height: 132px;
        opacity: 1;
      }
      width: 1240px;
      height: 0;
      padding: 0 20px;
      position: absolute;
      top: 36px;
      left: -194px;
      right: 0;
      background-color: #fff;
      box-shadow: 0 0 5px #ccc;
      transition: all 0.2s 0.1s;
      z-index: 1111;
      overflow: hidden;
      opacity: 0;
      ul {
        display: flex;
        flex-wrap: wrap;
        height: 132px;
        align-items: center;
        padding:  0 70px;
        li {
          width: 110px;
          // padding: 0 10px;
          margin: 0 ;
          text-align: center;
          img {
            width: 60px;
            height: 60px;
            margin-bottom: 5px;
          }
          a {
            &:hover {
              color: @xtxColor;
            }
          }
        }
      }
    }
}
</style>
